<?php
defined('IN_ADMIN') or exit('No permission resources.');
include $this->admin_tpl('header','admin');
?>
<div class="main-div">
<link type="text/css" rel="stylesheet" href="<?php echo CSS_PATH; ?>product/edit_hongbao.css" />
<style>
div.main-div {border:1px solid #bbdde5; margin:5px auto 10px auto; padding:2px; font-size:12px; width:660px;}
div.main-div table {margin:auto; text-align:center;}
</style>
<form method="post" action="?m=ushop&c=bonus&a=search_merchandise&menuid=<?php echo $_GET['menuid'];?>" id="theForm0">
<table width="100%">
<tr>
    <td class="label" style="text-align:left;">
    	商品名称：
        <input type="hidden" name="typeid" value="<?php echo $_REQUEST['mid']; ?>" />
        <input type="text" name="merchanidse" />
        <input type="submit" name="dosubmit" value="搜索" class="button" />
    </td>
</tr>
</table>
</form>
</div>
<form method="post" action="?m=ushop&c=bonus&a=send_bymerchandise&menuid=<?php echo $_GET['menuid'];?>" name="theForm" id="theForm"> 
<div class="main-div">
    <div class="list-div">
        <table cellspacing="1" cellpadding="3">
            <tbody>
                <tr>
                    <th>可选商品：</th>
                    <th>操作</th>
                    <th>发放此类型红包的商品</th>
                </tr>
                <tr>
                    <td width="45%" align="center">
                        <select multiple="true" style="width:260px" size="15" id="f_catids" onchange="javascript:addusers()">
                            <?php
                            foreach($info as $value) {
                            ?>
                                <option value="<?php echo $value['id'] ?>"><?php echo $value['title']; ?></option>
                            <?php
                            }
                            ?>
                        </select>
                    </td>
                    <td align="center">
                        <p style="margin-bottom:10px;">&nbsp;&nbsp;<input type="button" disabled="disabled" class="button" onclick="transact('update','f_catids','catids', '');" value="&gt;" id="adduser"></p>
                        <p>&nbsp;&nbsp;<input type="button" class="button" onclick="transact('delete','','catids','');" value="&lt;" id="deletebutton"></p>
                    </td>
                    <td width="45%" align="center">
                     	<input type="hidden" name="typeid" value="<?php echo $mid ?>" />
                        <select style="width:260px" size="15" multiple="true" id="catids" name="user[]"></select>
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right;" colspan="3"><input type="submit" class="button" value="确定发送红包" name="dosubmit" id="dosubmit" style="display:none;"></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
</form>
<script>
function addusers() {
	document.getElementById('adduser').disabled = false;
}
$("#dosubmit").click(function() {
	var len = $("#catids option").size();
	if(len<1) {
		alert('至少要添加一个会员');
		return false;
	}
	return true;
})

function transact(update,fromfiled,tofiled, num) {
	if(update=='delete') {
		var fieldvalue = $('#'+tofiled).val();
		$("#"+tofiled+" option").each(function() {
		   if($(this).val() == fieldvalue){
			$(this).remove();
		   }
		});
	} else {
		var fieldvalue = $('#'+fromfiled).val();
		var have_exists = 0;
		$("#"+tofiled+" option").each(function() {
		   if($(this).val() == fieldvalue){
			have_exists = 1;
			alert('已经添加到列表中');
			return false;
		   }
		});
		if(have_exists==0) {
			obj = $('#'+fromfiled+' option:selected');
			text = obj.text();
			text = text.replace('│', '');
			text = text.replace('├ ', '');
			text = text.replace('└ ', '');
			fieldvalue = "<option value='"+fieldvalue+"' selected='selected'>"+text+"</option>"
			$('#'+tofiled).append(fieldvalue);
			$('#deletebutton').attr('disabled','');
		}
	}
}

</script>
</body>
</html>